package com.shenma2009.utils;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author 军哥
 * @version 1.0
 * @description: RedissionLocker
 * @date 2023/4/27 10:56
 */

public class RedissionLocker {
    //--1
    public static RedissionLocker _instance = null;
    public static RedissonClient redissonClient = null;

    //--2 私有化构造函数
    private RedissionLocker() {
        Config config = new Config();
        //单机模式  依次设置redis地址和密码
        config.useSingleServer().
                setAddress("redis://" + "localhost" + ":" + 6379);
        redissonClient = Redisson.create(config);
    }

    public static RedissonClient getRedissonClient() {
        if(_instance == null) {
            _instance = new RedissionLocker();
            return redissonClient;
        }

        return redissonClient;
    }

}
